import axios from 'axios'
let qs = require('qs')
axios.defaults.timeout = 10000
axios.defaults.baseURL = 'https://jyapi.epanshi.com/api'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
axios.defaults.withCredentials = true
axios.interceptors.response.use( // 利用axios拦截器鉴权和写公共的错误分支
  response => {
    // console.log(response)
    return response
  },
  error => {
    console.log('服务器异常！')
  }
)
export default {
  fetchGet (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.get(url, {params}).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  fetchQuickSearch (url) {
    return new Promise((resolve, reject) => {
      axios.get(url).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  fetchPost (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.post(url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  fetchAll (params) {
    return new Promise((resolve, reject) => {
      axios.all([...params]).then(axios.spread((...results) => {
        resolve(results)
      })).catch(error => {
        reject(error)
      })
    })
  }
}
// 'https://jyapi.epanshi.com/api'
